﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

public partial class productdetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.menu.Logo = "1";

            if (null != Request.QueryString["c"])
            {
                InitTitle(Convert.ToInt32(Request.QueryString["c"].ToString()));
            }
            if (null != Request.QueryString["id"])
            {
                InitPath(Convert.ToInt32(Request.QueryString["id"].ToString()));
                InitContent(Convert.ToInt32(Request.QueryString["id"].ToString()));
            }
        }
    }

    private void InitTitle(int c)
    {
        CProduct product = new CProduct();
        DataRow r = product.Read(c);
        this.ltlTitle.Text = r["title"].ToString();
    }

    private void InitPath(int id)
    {
        CProduct p = new CProduct();
        List<string[]> lst = p.GetProductPath(id);
        StringBuilder sb = new StringBuilder();
        if (null != lst)
        {
            sb.Append(lst.Last()[1]);
            if (lst.Count > 2)
            {
                for (int i =lst.Count - 2 ; i >=1 ; i--)
                {
                    sb.Insert(0, "<a href=\"productcatlist.aspx?c=" + Request.QueryString["c"].ToString() + "&id=" + lst[i][0] + "\">" + lst[i][1] + "</a> > ");
                }
            }
            sb.Insert(0, "<a href=\"productcatlist.aspx?c=" + Request.QueryString["c"].ToString() + "\">" + lst[0][1] + "</a> > ");
        }
        this.ltlTopNav.Text = sb.ToString();
    }

    private void InitContent(int id)
    {
        CProduct p = new CProduct();
        DataRow r = p.Read(id);
        this.ltlContent.Text = r["content"].ToString();
    }
}